﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;


namespace BUS
{
    public class CT_SanBay_BUS
    {
        #region Truy van du lieu
        //Cac ham truy xuat du lieu
        public static List<CT_SanBay_DTO> layDanhSachCTSanBay()
        {
            return CT_SanBay_DAO.layDanhSachCTSanBay();
        }
        public static List<CT_SanBay_DTO> layCTSanBayTheoMaChuyenBay(String maCB)
        {
            if(CT_SanBay_DAO.kiemTraCTSB(maCB))
            {
                return layCTSanBayTheoMaChuyenBay(maCB);
            }
            return null;
        }
        
        public static List<CT_SanBay_DTO> layCTSanBayTheoLoaiSanBay(int loaiSB)
        {
            return CT_SanBay_DAO.layCTSanBayTheoLoaiSanBay(loaiSB);
        }

        #endregion
        //1-sbdi
        //2-sbden
        //3-sb trung gian

        #region Thao tac insert, update, delete
        //Cac ham tuong tac voi co so du lieu
        public static int themCTSanBay(CT_SanBay_DTO ctSanBay)    //them 1 bang chi tiet san bay
        {
            if (CT_SanBay_DAO.kiemTraCTSB(ctSanBay.maCB, ctSanBay.maSB))
            {
                return 2;
            }
            if (ctSanBay.loaiSB == 3)
            {
                if (CT_SanBay_DAO.kiemTraSoSBTrungGian(ctSanBay.maCB) || CT_SanBay_DAO.kiemTraTGianDung(ctSanBay.tGianDung))
                {
                    return 3;
                }
            }
            return CT_SanBay_DAO.themCTSanBay(ctSanBay)?1:0;
        }
        public static bool xoaCTSanBay(CT_SanBay_DTO ctSanBay)     //xoa 1 bang chi tiet san bay
        {
            if (CT_SanBay_DAO.kiemTraCTSB(ctSanBay.maCB, ctSanBay.maSB))
            {
                return CT_SanBay_DAO.xoaCTSanBay(ctSanBay);
            }
            return false;
            
        }
        public static bool suaCTSanBay(CT_SanBay_DTO ctSanBay)     //sua 1 bang chi tiet san bay
        {
            if (CT_SanBay_DAO.kiemTraCTSB(ctSanBay.maCB, ctSanBay.maSB) || CT_SanBay_DAO.kiemTraSoSBTrungGian(ctSanBay.maCB) || CT_SanBay_DAO.kiemTraTGianDung(ctSanBay.tGianDung))
            {
                return CT_SanBay_DAO.suaCTSanBay(ctSanBay);
            }
            return false;
        }
        #endregion
    }
}
